package com.liuheng.spzx.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.liuheng.spzx.model.entity.user.UserAddress;
import com.liuheng.spzx.model.entity.user.UserInfo;
import com.liuheng.spzx.model.vo.common.Result;
import com.liuheng.spzx.model.vo.common.ResultCodeEnum;
import com.liuheng.spzx.user.mapper.UserAddressMapper;
import com.liuheng.spzx.user.service.UserAddressService;
import com.liuheng.util.AuthContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/user/userAddress/")
public class UserAddressController {
    @Autowired
    private UserAddressMapper userAddressMapper;
    @GetMapping("/auth/findUserAddressList")
    public Result findUserAddressList(){
        UserInfo userInfo = AuthContextUtil.getUserInfo();
        LambdaQueryWrapper<UserAddress> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserAddress::getUserId,userInfo.getId());
        List<UserAddress> userAddressList = userAddressMapper.selectList(wrapper);
        return Result.build(userAddressList, ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/getUserAddress/{id}")
    public UserAddress getUserAddressById(@PathVariable Long id){
        UserAddress userAddress = userAddressMapper.selectById(id);
        return userAddress;
    }
}
